package com.cat.dynamicPlanning;

import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/word-break/description/
 * @create 2025/9/4 21:51
 * @since JDK17
 */

public class Solution72 {
    public boolean wordBreak(String s, List<String> wordDict) {
        int n = s.length(), m = wordDict.size();
        boolean[] dp = new boolean[n + 1];
        dp[0] = true;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < m; j++) {
                String w = wordDict.get(j);
                if (i >= w.length() && s.substring(i - w.length(), i).equals(w)) {
                    dp[i] = dp[i] || dp[i - w.length()];
                }
            }
        }

        return dp[n];
    }
}
